package com.ichir.projects.uiframework.tests.mocks;

import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Map;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;

import com.ichir.projects.uiflow.AbstractUiView;
import com.ichir.projects.uiflow.ApplicationContext;

/**
 * 
 * @author mahieddine_ichir
 */
public class View2 extends AbstractUiView {

	private JDialog dialog;
	
	@Override
	public void initializeView(final ApplicationContext context, Map<String, Object> attributes) {
		System.out.println(">> initialize view 2");
		dialog = new JDialog();
		dialog.setBounds(100, 100, 400, 400);
		
		dialog.setContentPane(new JPanel(new BorderLayout()));
		
		JButton close = new JButton("close");
		close.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				disposeView(context, null);
			}
		});

		JButton next = new JButton("next");
		next.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				fireEvent("vie1");
			}
		});

		dialog.getContentPane().add(close, BorderLayout.SOUTH);
		dialog.getContentPane().add(next, BorderLayout.NORTH);
		dialog.getContentPane().add(new JLabel("View 2"), BorderLayout.CENTER);
	}

	@Override
	public void refreshView(ApplicationContext context, Map<String, Object> attributes) {
		System.out.println(">> refresh view 2");
	}

	@Override
	public void showView(ApplicationContext context, Map<String, Object> attributes) {
		dialog.setVisible(true);
	}

	@Override
	public void disposeView(ApplicationContext context, Map<String, Object> attributes) {
		System.out.println(">> dispose view");
		dialog.dispose();
	}
}
